package im.yisme.model.fileio;

import im.yisme.model.Lyrics;
import im.yisme.model.LyricsRepository;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class LyricsRepositoryWriter {

	private String path;
	
	public LyricsRepositoryWriter(){
		path = DirManager.getRepositoryDir();
		createPath();
	}
	
	private void createPath(){
		File file = new File(path);
		file.mkdirs();
	}
	
	public void write(LyricsRepository lyricsRepository) throws IOException{
		File file = new File(path + "lyrics.repo");
		if (!file.exists()) file.createNewFile();
		PrintWriter writer = new PrintWriter(file);
		
		ArrayList<Lyrics> list = lyricsRepository.getRealList();
		for (int i=0; i<list.size(); i++){
			Lyrics lyrics = list.get(i);
			String info = lyrics.getId() + "&" + lyrics.getArtist() + "&" + lyrics.getName() + "&" + lyrics.getSource() + "&" +lyrics.getScore() + "&" +lyrics.getNoteNum() + "&" +lyrics.getTotalTime();
			writer.println(info);
		}
		
		writer.close();
	}
}
